<template>
  <div>
    <div class="header-back" v-show="flag">
       <span class="iconfont icon-return back-icon" @click="back"></span>
    </div>
    <div class="header-fixed" v-show="isclose" :style="opacityStyle">
       <span class="iconfont icon-return back-icon"  @click="back"></span>
       <div class="text">景点景区</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'detail-header',
  props: {
    flag: {
      type: Boolean
    }
  },
  data () {
    return {
      isclose: false,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  destroyed () {
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    back () {
      this.$router.push('/home')
    },
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.isclose = true
      } else {
        this.isclose = false
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~@/assets/styles/varibles.styl'
  .header-back
   position absolute
   left .2rem
   top .2rem
   width .8rem
   height .8rem
   line-height .8rem
   border-radius 50%
   background rgba(0,0,0,.4)
   text-align center
   .back-icon
    font-size .5rem
    color #fff
  .header-fixed
   position fixed
   top 0
   left 0
   right 0
   display flex
   height $headerHeight
   line-height $headerHeight
   background-color $bgColor
   color $color
   text-align center
   .back-icon
    display block
    width .64rem
    font-size .5rem
   .text
    text-align center
    margin-left 2.6rem
</style>
